<template>
  <div class="RootLoading">
    <div v-if="!loading">
        用户信息获取失败请联系管理员
    </div>
    <div v-else>
        加载中...
    </div>
  </div>
</template>

<script>
import{Init,getcodev2,getopenid} from '@/api/admin.js'
import {setwxstate,getwxstate,delwxstate} from '@/utils/auth.js'
export default {
    data() {
        return {
            loading:true
        }
    },
created() {
    Init().then(response=>{
        if(response.code==200){
            if(response.data.force_bind_wechat=='是'){
                this.$store.dispatch('user/wxlogin').then(res=>{
                    if(res.code==200){
                        document.title='账号绑定'
                        // window.open(res.data,'_self')
                        // this.$router.push('/wxbind')
                        if(getwxstate()&&getwxstate()!='undefined'){
                            getopenid({state:getwxstate()}).then(res=>{
                                this.$router.push('/wxbind')
                            }).catch(res=>{
                                delwxstate()
                                getcodev2().then(res=>{
                                    if(res.code==200){
                                        setwxstate(res.data.state)
                                        window.open(res.data.url,'_self')
                                    }
                                })
                            })
                        }else{
                            getcodev2().then(res=>{
                                if(res.code==200){
                                   setwxstate(res.data.state)
                                   window.open(res.data.url,'_self')
                                }
                            })
                        }
                    }else{
                        this.loading=false
                    }
                })
            }else{
                // document.title='账号登录'
                this.$router.push('/wxlogin')
            }
        }else{
            this.$toast.fail('系统初始化失败,请联系管理员')
        }
    })
    
},
}
</script>

<style lang="scss" scoped>
.RootLoading{
    height:100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    padding:24px;
}
</style>>
